package com.ifdom.thread.threadpoolworkqueue;

import java.util.concurrent.*;

/**
 * 4种方式，创建线程池工作队列
 *
 * @Author ifredomvip@gmail.com
 * @Date 2022/10/4 10:44
 * @Version 1.0.0
 * @Description
 **/
public class WorkQueue4Mode {

    public static void main(String[] args) {
//        // 1.直接提交队列
        ExecutorService executorService1 = new ThreadPoolExecutor(0,
                2,
                300,
                TimeUnit.SECONDS,
                new SynchronousQueue<>(),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

//        // 2.有界执行队列
//        ExecutorService executorService2 = new ThreadPoolExecutor(1,
//                2,
//                300,
//                TimeUnit.SECONDS,
//                new ArrayBlockingQueue<>(5),
//                Executors.defaultThreadFactory(),
//                new ThreadPoolExecutor.AbortPolicy()
//        );
//
//
//        // 3.无界执行队列
//        ExecutorService executorService3 = new ThreadPoolExecutor(1,
//                2,
//                300,
//                TimeUnit.SECONDS,
//                new LinkedBlockingQueue<>(),
//                Executors.defaultThreadFactory(),
//                new ThreadPoolExecutor.AbortPolicy()
//        );

        // 4.优先任务队列
//        ExecutorService executorService4 = new ThreadPoolExecutor(0,
//                2,
//                1000,
//                TimeUnit.SECONDS,
//                new PriorityBlockingQueue<>(),
//                Executors.defaultThreadFactory(),
//                new ThreadPoolExecutor.AbortPolicy()
//        );

        // 执行任务
        for (int i = 10; i >=0; i--) {
            executorService1.execute(new PriorityTaskHandle(i));
        }

        executorService1.shutdown();

    }
}
